package cn.edu.scau.cmi.wuzewei.comprehensive;

import cn.edu.scau.cmi.wuzewei.adapter.ClassPowerAdapter;
import cn.edu.scau.cmi.wuzewei.adapter.ObjectPowerAdapter;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.stage.Stage;

public class AdapterWindow {
	public void newWindow(Stage primaryStage) {
		
		Group group = new Group();
		
		TextArea textArea1 = new TextArea();
		textArea1.setLayoutX(80);
		textArea1.setLayoutY(150);
		textArea1.setMaxWidth(160);
		textArea1.setMaxHeight(100);
		group.getChildren().add(textArea1);
		
		TextArea textArea2 = new TextArea();
		textArea2.setLayoutX(300);
		textArea2.setLayoutY(150);
		textArea2.setMaxWidth(160);
		textArea2.setMaxHeight(100);
		group.getChildren().add(textArea2);
		
		Button button1 = new Button("类适配器模式");
		button1.setLayoutX(120);
		button1.setLayoutY(100);
		button1.setOnAction(new EventHandler<ActionEvent>() {
			@Override
			public void handle(ActionEvent event) {
				ClassPowerAdapter classPowerAdapter = new ClassPowerAdapter();
				textArea1.setText(classPowerAdapter.charging110v());
			}
		});
		group.getChildren().add(button1);
		
		Button button2 = new Button("对象适配器模式");
		button2.setLayoutX(330);
		button2.setLayoutY(100);
		button2.setOnAction(new EventHandler<ActionEvent>() {
			@Override
			public void handle(ActionEvent event) {
				ObjectPowerAdapter objectPowerAdapter = new ObjectPowerAdapter();
				textArea2.setText(objectPowerAdapter.charging110v());
			}
		});
		group.getChildren().add(button2);
		
		Scene scene = new Scene(group);
		primaryStage.setTitle("实验四：适配器模式");
		primaryStage.setWidth(600);
		primaryStage.setHeight(400);
		primaryStage.setScene(scene);
		primaryStage.show();
	}
}
